const globalIp = getApp().globalData.userIp
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list:[]
  },

  freeback(e) {
    var that = this;
    wx.showModal({
      editable:true,//显示输入框
      placeholderText:'输入意见回复',//显示输入框提示信息
      success: res => {
        if (res.confirm) { //点击了确认
          let param = {};
          param.number = e.currentTarget.dataset.number;
          param.value = res.content;
          that.confirm(param);
        } else {
          console.log('用户点击了取消')
        }
      }
    })
  },

  confirm: function(param){
    var that = this;
    wx.request({
      url: globalIp + 'home/updateXCXO',
      data: {
        docEntry: param.number || '',
        value: param.value || '',
        openId: wx.getStorageSync('userInfo').openid || ''
      },
      header: {
        'content-type': 'application/json'
      },
      method: 'POST',
      success: function(res) {
        if (res.data.success) {
          wx.showToast({
            title: '回复意见成功！',
            icon: 'success',
            success: function(res) {
              setTimeout(() => {
                that.onShow()
              }, 1000)
            }
          })
        } else {
          wx.showToast({
            title: res.data.msg,
            icon: 'none',
            duration: 2000
          })
        }
      }
    })
  },

  submit: function(){
    var that = this;
    wx.request({
      url: globalIp + 'home/selectOpinion',
      data: {
        openId: wx.getStorageSync('userInfo').openid || '' 
      },
      header: {
        'content-type': 'application/json'
      },
      method: 'POST',
      success: function(res) {
        if (res.data.success) {
          console.log(res.data)
          that.setData({
            list: res.data.JSONObject.data
          })
        } else {
          wx.showToast({
            title: res.data.msg,
            icon: 'none',
            duration: 2000
          })
        }
      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.submit()
  },

})